<?php
error_reporting(0);
set_time_limit (0);
include_once(dirname(__FILE__).'/dbutil.php');
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
if(isset($_POST['name'])){
	$cookie_jar = dirname(__FILE__).'/tmp.txt';//tempnam('./tmp','cookie');
	// 登录
	if(!empty($_POST['name'])){
		login_post('https://www.kujiale.com/api/login',$cookie_jar,array('email'=>$_POST['name'],'password'=>$_POST['pwd'],'account'=>$_POST['name']));
		sleep(2);
	}
	$db = new DBUtil();
	$sql = "SELECT id,house_name  FROM t_house where status<>2";
	//$db->query($sql);
	$house = $db->getOneRow($sql);
	// 没有未抓取楼盘
	if(empty($house)){
		echo 'finish';
		exit;
	}
	$houseId = $house['id'];
	// 小区名字
	$name = $house['house_name'];
	// 开始抓，更改状态
	$sql = 'update t_house set status = 1 where id = ' . $house['id'];
	$db->query($sql);
	$start = 0;
	$end = 60;
	// 抓户型的总数
	$cnt = 0;
	$flag = true;
	while(true){
		// 搜小区户型
		$url = 'https://www.kujiale.com/vc/api/floorplan?query=dalian-'.$name.'&start='.$start.'&num='.$end;
		//sleep(3);
		$data = get_content($url,$cookie_jar,'https://www.kujiale.com/vc/design/search');
		$data = json_decode($data,true);
		
		// 遍历小区户型
		foreach($data['obsExFps'] as $item){
			//var_dump($item['srcType']);exit;
			// 非公共户型，第一步先不抓
			//var_dump($item['srcType']);
			if($item['srcType'] != '0'){
				$flag = false;
				break;
			}
			// 判断户型是否存在
			$sql = "select * from t_sys_layout where commID = '".$db->escape($houseId)."' and lid = '".$db->escape($item['obsPlanId'])."'";
			$tmpData = $db->getOneRow($sql);
			if(!empty($tmpData)){
				continue;
			}
			$file_dir = dirname(__FILE__).'/images/layout/dalian/'.$houseId;
			if(!file_exists($file_dir)){
				mkdir($file_dir);
			}
			$record = array();
			$record['id'] = guid();
			$record['lid'] = $item['obsPlanId'];
			$record['commID'] = $houseId;
			$record['area'] = $item['srcArea'];
			$record['specName'] = $item['name'];
			$jpg = $item['pics'];
			//var_dump($jpg);
			$image = http_request($jpg);
			//var_dump($image);exit;
			file_put_contents($file_dir.'/'.$record['id'] .'.jpg', $image);
			// 图片
			$record['pics'] = '/images/layout/dalian/'.$houseId.'/'.$record['id'].'.jpg';
			// 户型面积
			//$record['specName'] = $zroom['name'];
			(saveRecord('t_sys_layout',$record,$db));
			//exit;
			/*$record = array();
			$record['house_id'] = $house['id'];
			$record['room_code'] = $item['obsPlanId'];
			$record['src_area'] = $item['srcArea'];
			$record['area'] = $item['area'];
			$record['real_area'] = $item['realArea'];
			$record['name'] = $item['specName'];
			$record['status'] = 0;
			saveRecord('t_sys_layout',$record,$db);
			// 保存jpg
			$jpg = $item['pics'];
			$image = file_get_contents($jpg); 
			file_put_contents($file_dir.'/'.$code .'.jpg', $image);*/
			/*// 获取跳转的参数（酷家乐自己的逻辑）
			$url = 'https://www.kujiale.com/api/floorplans/'.$item['obsPlanId'];
			$id=post_content($url,$cookie_jar,array('id'=>$item['obsPlanId'],'floorplanname'=>$name),'https://www.kujiale.com/vc/design/search');
			// 跳转到户型界面
			$url = 'https://www.kujiale.com/vc/flash/floorplan?obsplanid='.$id.'&redirecturl=https://www.kujiale.com/vc/design/all';
			get_content($url,$cookie_jar);
			// 生成装修方案
			$url = 'https://yun.kujiale.com/diy/deco?obsplanid='.$id.'&redirecturl=https%3A%2F%2Fwww.kujiale.com%2Fvc%2Fdesign%2Fall';
			(get_content($url,$cookie_jar,'https://www.kujiale.com/vc/flash/floorplan?obsplanid='.$id.'&redirecturl=https://www.kujiale.com/vc/design/all'));
			save($house,$db,$cookie_jar);
			$cnt++;
			if($cnt  > 20){
				echo '共新建了'.$cnt.'个户型；达到上限。';
				exit;
			}
			// 一个户型图中间暂停20分钟-30分钟
			$t = rand(1200,1800);
			sleep($t);*/
			sleep(5);
		}
		/*// 下载最后一张户型图
		save($house,$db,$cookie_jar);
		$cnt++;
		if($cnt  > 20){
			echo '共新建了'.$cnt.'个户型；达到上限。';
			exit;
		}*/
		if($flag && $data['hasMore']){
			$start += 60;
			$end += 60;
		}else{
			break;
		}
	}
	//echo 1;exit;
	// 抓完，更新状态
	$sql = 'update t_house set status = 2 where id = ' . $house['id'];
	$db->query($sql);
}

 function http_request($url, $data = null){
        $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $url);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
         }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         $info = curl_exec($curl);
         curl_close($curl);
        return $info;
    }
function guid(){
    mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);// "-"
        $uuid = //chr(123)// "{"
                substr($charid, 0, 8)
                .substr($charid, 8, 4)
                .substr($charid,12, 4)
                .substr($charid,16, 4)
                .substr($charid,20,12);
                //.chr(125);// "}"
        return $uuid;
}
function save($house,$db,$cookie_jar){
	// 获取装修方案
	$url = 'https://www.kujiale.com/vc/api/design?query=&page=1&start=0&num=20&type=2';
	$designData = get_content($url,$cookie_jar);
	$designData = json_decode($designData,true);
	// 遍历所有装修方案
	foreach($designData['designs']  as $itm){
		$id = $itm['obsDesignId'];
		$code = $itm['obsPlanId'];
		// 方案状态
		$url = 'https://www.kujiale.com/api/design/'.$id.'/constructiondesign';
		
		$tmp =json_decode(get_content($url,$cookie_jar,''),true);
		/*if($house['house_name'] != $itm['communityName']){
			continue;
		}*/
		// 户型图保存位置
		$file_dir = dirname(__FILE__).'/huxingtu/'.mb_convert_encoding($itm['communityName'],'gbk','utf-8');
		//var_dump($file_dir);
		//var_dump($tmp);
		// 没有户型图或者生成失败
		if($tmp['status'] == -1 || $tmp['status'] == 3){
			// 生成户型图
			$url = 'https://www.kujiale.com/api/design/'.$id.'/constructiondesign';
			post_json($url,$cookie_jar,array(20));
		}
		// 户型图未生成
		else if(empty($tmp['constructionUrl'])){
			continue;
		}
		// 户型图未下载
		else if(!file_exists($file_dir.'/'.$code .'.zip')){
			if(!file_exists($file_dir)){
				mkdir($file_dir);
			}
			// 保存jpg
			$jpg = $itm['coverPic'];
			$image = file_get_contents($jpg); 
			file_put_contents($file_dir.'/'.$code .'.jpg', $image);
			// 保存CAD
			dowload($tmp['constructionUrl'],$file_dir.'/'.$code .'.zip',$cookie_jar);
			// 解压CAD
			unzip($code,$file_dir);
			//$record = array();
			//$record['house_id'] = $house['id'];
			//$record['room_code'] = $code;
			//$record['status'] = 1;
			// 更新状态
			$sql = "update t_room set status = 1 where room_code = '" . $code . "'";
			$db->query($sql);
			//saveRecord('t_room',$record,$db);
		}
		// 户型图已下载，直接退出
		else{
			continue;
		}
		// 下载户型图中间间隔10s
		sleep(10);
	}
}

function saveRecord($table,$record,$db){
    	if(empty($table))
    		return false;
    	if(!is_array($record) || empty($record))
    		return false;
    	//$this->initDB();
    	$r = array();
    	foreach($record as $key=>$item){
    		$r[$db->escape($key)] = $db->escape($item);
    	}
    	$cols = implode("," , array_keys($r));
    	$values = implode("','" , $r);
    	$sql = "insert into " . $db->escape($table) . " (" . $cols . ") values ('" . $values . "')";
    	return $db->query($sql) ? $db->getlastid() : false;
}

function updateRecord($table,$record,$key,$value,$db){
    	if(empty($table))
    		return false;
    	if(!is_array($record) || empty($record))
    		return false;
    	//$this->initDB();
    	$arr = array();
    	foreach($record as $key=>$item){
    		$arr[] = $db->escape($key) . " = '" . $db->escape($item) . "' ";
    	}
    	$sets = implode("," , $arr);
    	$sql = "update " . $db->escape($table) . " set " . $sets . " where ".$db->escape($key)." = '" . $db->escape($value) . "'";
    	return $db->query($sql);
}

//模拟登录 
function login_post($url, $cookie, $post) {
	//var_dump($post);exit;
	$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36";
	/*if ($curl_loops++ >= $curl_max_loops) {
		$curl_loops = 0;
		return false;
	}*/
	$header = array("Referer: https://www.kujiale.com/"); 
	  $curl = curl_init();//初始化curl模块 
	  curl_setopt($curl, CURLOPT_URL, $url);//登录提交的地址 
	  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
	  curl_setopt($curl, CURLOPT_HEADER, 1);//是否显示头信息 
	  curl_setopt($curl, CURLOPT_HTTPHEADER,$header); 
	  //curl_setopt ($curl,CURLOPT_REFERER,'http://www.kujiale.com/');
	  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//是否自动显示返回的信息 
	  curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie); //设置Cookie信息保存在指定的文件中 
	  curl_setopt($curl, CURLOPT_POST, 1);//post方式提交 
	  curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));//要提交的信息 
	  //curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
	  
	  curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
	  //curl_setopt($curl, CURLOPT_REFERER, 'https://www.kujiale.com/');
	  $data = curl_exec($curl);//执行cURL 
	  $ret = $data;
	  list($header, $data) = explode("\r\n\r\n", $data, 2);
	  $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
	  $last_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
	  //var_dump($output);
	  $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE); 
	  //var_dump($httpCode);
	  //echo '<hr/>';
	  curl_close($curl);//关闭cURL资源，并且释放系统资源 
	  if ($http_code == 301 || $http_code == 302) {
	  	  $matches = array();
	  	  preg_match('/Location:(.*?)\n/', $header, $matches);
	  	  $url = @parse_url(trim(array_pop($matches)));
	  	  if (!$url) {
	  	  	  $curl_loops = 0;
	  	  	  return $data;
	  	  }
	  	  $new_url = $url['scheme'] . '://' . $url['host'] . $url['path']
	  	  	  . (isset($url['query']) ? '?' . $url['query'] : '');
	  	  $new_url = stripslashes($new_url);
	  	  return login_post($new_url,$cookie, $post);
	 } else {
	 	 $curl_loops = 0;
	 	 list($header, $data) = explode("\r\n\r\n", $ret, 2);
	 	 return $data;
	 }
} 

function post_content($url, $cookie, $post,$referfer='') {
	//var_dump($post);exit;
	$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36";
	/*if ($curl_loops++ >= $curl_max_loops) {
		$curl_loops = 0;
		return false;
	}*/
	if($referfer == ''){
		$referfer = 'https://www.kujiale.com/';
	}
	$header = array("Referer: ".$referfer); 
	  $curl = curl_init();//初始化curl模块 
	  curl_setopt($curl, CURLOPT_URL, $url);//登录提交的地址 
	  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
	  curl_setopt($curl, CURLOPT_HEADER, 1);//是否显示头信息 
	  curl_setopt($curl, CURLOPT_HTTPHEADER,$header); 
	  //curl_setopt ($curl,CURLOPT_REFERER,'http://www.kujiale.com/');
	  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//是否自动显示返回的信息 
	  curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); //设置Cookie信息保存在指定的文件中 
	  curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie); //设置Cookie信息保存在指定的文件中 
	  curl_setopt($curl, CURLOPT_POST, 1);//post方式提交 
	  curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));//要提交的信息 
	  //curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
	  
	  curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
	  //curl_setopt($curl, CURLOPT_REFERER, 'http://www.kujiale.com/');
	  $data = curl_exec($curl);//执行cURL 
	  $ret = $data;
	  list($header, $data) = explode("\r\n\r\n", $data, 2);
	  $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
	  $last_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
	  //var_dump($output);
	  $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE); 
	  //var_dump($httpCode);
	  curl_close($curl);//关闭cURL资源，并且释放系统资源 
	  if ($http_code == 301 || $http_code == 302) {
	  	  $matches = array();
	  	  preg_match('/Location:(.*?)\n/', $header, $matches);
	  	  $url = @parse_url(trim(array_pop($matches)));
	  	  if (!$url) {
	  	  	  $curl_loops = 0;
	  	  	  return $data;
	  	  }
	  	  $new_url = $url['scheme'] . '://' . $url['host'] . $url['path']
	  	  	  . (isset($url['query']) ? '?' . $url['query'] : '');
	  	  $new_url = stripslashes($new_url);
	  	  return login_post($new_url,$cookie, $post);
	 } else {
	 	 $curl_loops = 0;
	 	 list($header, $data) = explode("\r\n\r\n", $ret, 2);
	 	 return $data;
	 }
} 

function post_json($url, $cookie, $post,$referfer='') {
	$post = json_encode($post);
	//var_dump($post);exit;
	$useragent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
	/*if ($curl_loops++ >= $curl_max_loops) {
		$curl_loops = 0;
		return false;
	}*/
	if($referfer == ''){
		$referfer = 'https://www.kujiale.com/';
	}
	$header = array("Referer: ".$referfer); 
	  $curl = curl_init();//初始化curl模块 
	  curl_setopt($curl, CURLOPT_URL, $url);//登录提交的地址 
	  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
	  curl_setopt($curl, CURLOPT_HEADER, 1);//是否显示头信息 
	  curl_setopt($curl, CURLOPT_HTTPHEADER,$header); 
	  //curl_setopt ($curl,CURLOPT_REFERER,'http://www.kujiale.com/');
	  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//是否自动显示返回的信息 
	  curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); //设置Cookie信息保存在指定的文件中 
	  curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie); //设置Cookie信息保存在指定的文件中 
	  curl_setopt($curl, CURLOPT_POST, 1);//post方式提交 
	  curl_setopt($curl, CURLOPT_POSTFIELDS, $post);//要提交的信息 
	  curl_setopt($curl, CURLOPT_HTTPHEADER, array(
		    'Content-Type: application/json',
		    'Content-Length: ' . strlen($post))
		);
	  //curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
	  
	  curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
	  //curl_setopt($curl, CURLOPT_REFERER, 'http://www.kujiale.com/');
	  $data = curl_exec($curl);//执行cURL 
	  $ret = $data;
	  list($header, $data) = explode("\r\n\r\n", $data, 2);
	  $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
	  $last_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
	  //var_dump($output);
	  $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE); 
	  //var_dump($httpCode);
	  curl_close($curl);//关闭cURL资源，并且释放系统资源 
	  if ($http_code == 301 || $http_code == 302) {
	  	  $matches = array();
	  	  preg_match('/Location:(.*?)\n/', $header, $matches);
	  	  $url = @parse_url(trim(array_pop($matches)));
	  	  if (!$url) {
	  	  	  $curl_loops = 0;
	  	  	  return $data;
	  	  }
	  	  $new_url = $url['scheme'] . '://' . $url['host'] . $url['path']
	  	  	  . (isset($url['query']) ? '?' . $url['query'] : '');
	  	  $new_url = stripslashes($new_url);
	  	  return login_post($new_url,$cookie, $post);
	 } else {
	 	 $curl_loops = 0;
	 	 list($header, $data) = explode("\r\n\r\n", $ret, 2);
	 	 return $data;
	 }
} 

function get_content($url, $cookie,$referfer='') {
	//var_dump($post);exit;
	$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36";
	/*if ($curl_loops++ >= $curl_max_loops) {
		$curl_loops = 0;
		return false;
	}*/
	if($referfer == ''){
		$referfer = 'https://www.kujiale.com/';
	}
	$header = array("Referer: ".$referfer); 
	  $curl = curl_init();//初始化curl模块 
	  curl_setopt($curl, CURLOPT_URL, $url);//登录提交的地址 
	  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
	  curl_setopt($curl, CURLOPT_HEADER, 1);//是否显示头信息 
	  curl_setopt($curl, CURLOPT_HTTPHEADER,$header); 
	  //curl_setopt ($curl,CURLOPT_REFERER,'http://www.kujiale.com/');
	  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//是否自动显示返回的信息 
	  curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); //设置Cookie信息保存在指定的文件中 
	  curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie); //设置Cookie信息保存在指定的文件中 
	  //curl_setopt($curl, CURLOPT_POST, 1);//post方式提交 
	  //curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));//要提交的信息 
	  //curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
	  
	  curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
	  //curl_setopt($curl, CURLOPT_REFERER, 'http://www.kujiale.com/');
	  $data = curl_exec($curl);//执行cURL 
	  $ret = $data;
	  list($header, $data) = explode("\r\n\r\n", $data, 2);
	  $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
	  $last_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
	  //var_dump($output);
	  $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE); 
	  //var_dump($httpCode);
	  //echo '<hr/>';
	  curl_close($curl);//关闭cURL资源，并且释放系统资源 
	  if ($http_code == 301 || $http_code == 302) {
	  	  $matches = array();
	  	  preg_match('/Location:(.*?)\n/', $header, $matches);
	  	  $url = @parse_url(trim(array_pop($matches)));
	  	  if (!$url) {
	  	  	  $curl_loops = 0;
	  	  	  return $data;
	  	  }
	  	  $new_url = $url['scheme'] . '://' . $url['host'] . $url['path']
	  	  	  . (isset($url['query']) ? '?' . $url['query'] : '');
	  	  $new_url = stripslashes($new_url);
	  	  return get_content($new_url,$cookie);
	 } else {
	 	 $curl_loops = 0;
	 	 list($header, $data) = explode("\r\n\r\n", $ret, 2);
	 	 return $data;
	 }
} 

function dowload($url, $file="", $cookie,$timeout=3600) {
  $file = empty($file) ? pathinfo($url,PATHINFO_BASENAME) : $file;
  $dir = pathinfo($file,PATHINFO_DIRNAME);
  !is_dir($dir) && @mkdir($dir,0755,true);
  $url = str_replace(" ","%20",$url);
  $temp = get_content($url,$cookie);
    @file_put_contents($file, $temp);
}
function unzip($file, $path) {
	$filename = $path . '/'.$file.'.zip';
	 //先判断待解压的文件是否存在
	 if(!file_exists($filename)){
	 	 return false;
	 }
	 //打开压缩包
	 $resource = zip_open($filename);
	 $i = 1;
	 //遍历读取压缩包里面的一个个文件
	 while ($dir_resource = zip_read($resource)) {
		  //如果能打开则继续
		  if (zip_entry_open($resource,$dir_resource)) {
			   //获取当前项目的名称,即压缩包里面当前对应的文件名
			   $file_name = $path.zip_entry_name($dir_resource);
			   //以最后一个“/”分割,再用字符串截取出路径部分
			   $file_path = substr($file_name,0,strrpos($file_name, "/"));
			   //var_dump($file_name);
			   //如果路径不存在，则创建一个目录，true表示可以创建多级目录
			   if(!is_dir($file_path)){
			    	mkdir($file_path,0777,true);
			   }
			   //如果不是目录，则写入文件
			   if(!is_dir($file_name) && substr($file_name, -4) == '.dxf'){
				    //读取这个文件
				    $file_size = zip_entry_filesize($dir_resource);
				    $file_content = zip_entry_read($dir_resource,$file_size);
				     file_put_contents($path . '/'.$file.'.dxf',$file_content);
			   }
			   //关闭当前
			   zip_entry_close($dir_resource);
		  }
	 }
	 //关闭压缩包
	 zip_close($resource);
}
//登录成功后获取数据 
/*function get_content($url, $cookie) { 
	  $ch = curl_init(); 
	  curl_setopt($ch, CURLOPT_URL, $url); 
	  curl_setopt($ch, CURLOPT_HEADER, 1); 
	  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//是否自动显示返回的信息 
	  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //读取cookie 
	  curl_setopt($ch, CURLOPT_REFERER, 'http://www.kujiale.com/');
	  $rs = curl_exec($ch); //执行cURL抓取页面内容 
	  $httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE); 
	  var_dump($httpCode);
	  curl_close($ch); 
	  return $rs; 
} */
?>
<?php if(true){?>
<form id="form" action='' method='post'>
用户名：<input type="text" name="name" value=""/><br/>
密码：<input type="text" name="pwd" value=""/><br/>
	<input type="submit" value="开始抓取数据"/>
</form>
<script>
	setTimeout(function(){
		document.getElementById('form').submit();
	},1000*5);
</script>
<?php }?>